<!--#include file="conn.asp"-->
<!--#include file="chkuser.asp"-->
<%
call adminRight(9)
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>上传文件管理</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <div id="frame_Toolbar" class="toolbarBg"> 
		<a href="javascript:self.history.back();" class="icoBtn_ct"><span class="btnIco btnBack"></span>返回</a> 
		<a href="javascript:self.location.reload();" class="icoBtn_ct"><span class="btnIco btnReload"></span>刷新</a> 
		<span class="split ftSplit" ></span>
	    <div id="guide"></div>
    </div>
	<div id="MainContent">
<table class="cTable_2 table">
  <tr class="cTitle toolbarBg">
	<td><div class="cLeftPadding">上 传 文 件 管 理</div></td>
  </tr>
</table>
<%
action=trim(request("action"))
goDir=trim(request("goDir"))

if action="Del" then 
	if DelFile(Request("FileName"))=True then call ShowMessage("<br><b>"&Request("FileName")&"<br>文件已永久删除！</b>","parent",3000,0,"","")
end if
if action="DelFolder" then 
	if DelFolder(Request("FolderName"))=True then call ShowMessage("<br><b>"&Request("FolderName")&"<br>目录已永久删除！</b>","parent",3000,0,"","")
end if
	
Const MaxPerPage=20
dim strFileName
dim totalPut,CurrentPage,TotalPages
dim UploadDir,TruePath,fso,theFolder,theFile,whichfile,thisfile,FileCount,TotleSize
strFileName="UploadFileManage.asp"

SaveUpFilesPath=replace(replace(UploadSavePath_con,"../",""),"./","")
if right(SaveUpFilesPath,1)="/" then SaveUpFilesPath=mid(SaveUpFilesPath,1,(len(SaveUpFilesPath)-1))

if goDir<>"" then SaveUpFilesPath=goDir

if request("page")<>"" then
    currentPage=cint(request("page"))
else
	currentPage=1
end if

if right(SaveUpFilesPath,1)<>"/" then
	UploadDir="../" & SaveUpFilesPath & "/"
else
	UploadDir="../" & SaveUpFilesPath
end if
TruePath=Server.MapPath(UploadDir)
If not IsObjInstalled("Scripting.FileSystemObject") Then
	Response.Write "<b><font color=red>你的服务器不支持 FSO(Scripting.FileSystemObject)! 不能使用本功能</font></b>"
Else
	set fso=CreateObject("Scripting.FileSystemObject")

%>
<table width="95%" align="center" border="0" cellpadding="5" cellspacing="0">
  <tr> 
    <td><strong>当前目录：网站根目录<%
	arrPath=split(SaveUpFilesPath,"/")
	for arrPath_i=0 to ubound(arrPath)
	    thisGoDir=""
		for arrPath_j=0 to arrPath_i
			if thisGoDir="" then
				thisGoDir=arrPath(arrPath_j)
			else
				thisGoDir=thisGoDir&"/"&arrPath(arrPath_j)
			end if
		next
	    response.Write "\<a href='?goDir="&thisGoDir&"' title='点击进入' style='text-decoration:underline'>"&arrPath(arrPath_i)&"</a>"
	next
	%></strong></td>
  </tr>
  <tr> 
    <td>
	<%
	if fso.FolderExists(TruePath) then
		Set thisFolder = fso.GetFolder(TruePath)
		Set thisFolderSources = thisFolder.SubFolders
		response.Write "<strong>当前目录下的子目录："&thisFolderSources.count&"个</strong>"
		if thisFolderSources.count<=30 then
		response.Write("<br>")
		%>
			<%For Each folderName in thisFolderSources%>
				<div class="left">
				<table>
				  <tr>
				    <td><span class="fileIco fileFolder">&nbsp;</span></td>
				    <td style="white-space:nowrap; "><a href="?goDir=<%=SaveUpFilesPath&"/"&folderName.name%>" title="点击进入"><%=folderName.name%></a> <a href="?action=DelFolder&FolderName=<%=UploadDir&folderName.name%>&goDir=<%=goDir%>" onClick="return confirm('确定删除该子目录及该子目录下的所有文件？')" style="color:#FF6600; padding-right:3px">删</a></td>
				  </tr>
				</table>
				</div>
			<%Next%>
		<%else%>
			<select id="goSelect">
			   <%For Each folderName in thisFolderSources%>
			   <option value="<%=SaveUpFilesPath&"/"&folderName.name%>"><%=folderName.name%></option>
			   <%Next%>
			</select>
			<input type="button" value="跳转到该目录" style="border:0px;background-color:#cccccc;padding:2px" onClick="location='?goDir='+document.getElementById('goSelect').value"> 
			<input type="button" value="删除该目录" style="border:0px;background-color:#cccccc;padding:2px" onClick="location='?action=DelFolder&goDir=<%=goDir%>&FolderName=../'+document.getElementById('goSelect').value">
		<%end if%>
	<%
	End if
	%>
   </td>
  </tr>
</table>
  <%
  if fso.FolderExists(TruePath) then
	FileCount=0
	TotleSize=0
	Set theFolder=fso.GetFolder(TruePath)
	For Each theFile In theFolder.Files
		FileCount=FileCount+1
		TotleSize=TotleSize+theFile.Size
	next
    totalPut=FileCount
	if currentpage<1 then
   		currentpage=1
   	end if
   	if (currentpage-1)*MaxPerPage>totalput then
		if (totalPut mod MaxPerPage)=0 then
	  		currentpage= totalPut \ MaxPerPage
	  	else
	      	currentpage= totalPut \ MaxPerPage + 1
		end if

    end if
	if currentPage=1 then
		showpage2 strFileName,totalput,MaxPerPage
		showContent     	
		showpage2 strFileName,totalput,MaxPerPage
		response.write "<br><div align='center'>本页共显示 <b>" & FileCount & "</b> 个文件，占用 <b>" & TotleSize\1024 & "</b> K</div>"
   	else
   	   	if (currentPage-1)*MaxPerPage<totalPut then
			showpage2 strFileName,totalput,MaxPerPage
			showContent     	
			showpage2 strFileName,totalput,MaxPerPage
			response.write "<br><div align='center'>本页共显示 <b>" & FileCount & "</b> 个文件，占用 <b>" & TotleSize\1024 & "</b> K</div>"
       	else
        	currentPage=1
			showpage2 strFileName,totalput,MaxPerPage
			showContent     	
			showpage2 strFileName,totalput,MaxPerPage
			response.write "<br><div align='center'>本页共显示 <b>" & FileCount & "</b> 个文件，占用 <b>" & TotleSize\1024 & "</b> K</div>"
    	end if
	end if
  else
	response.write "<p align='center' style='color:#ff0000;font-weight:bold'>Error：找不到文件夹！可能是配置有误！</p>"
  end if
end if

sub showContent()
   	dim c
	FileCount=0
	TotleSize=0
%> 
      <table width="95%" border="0" align="center" cellpadding="0" cellspacing="1">
        <tr bgcolor="#dbe5eb"> 
          <td height="25" align="center"><strong>文件名</strong></td>
          <td align="center"><strong>文件大小</strong></td>
          <td align="center"><strong>文件类型</strong></td>
          <td align="center"><strong>最后修改时间</strong></td>
          <td align="center"><strong>操作</strong></td>
        </tr>
        <%
		For Each theFile In theFolder.Files
			c=c+1
			if FileCount>=MaxPerPage then
				exit for
			elseif c>MaxPerPage*(CurrentPage-1) then
		%>
				<tr bgcolor="#f5f8fa"> 
				  <td height="22" align="center" style="padding:0 15px 0 30px; white-space:nowrap">
				  <a href="<%=(UploadDir & theFile.Name)%>" target="_blank" style="float:left;"><%call getFileIco(theFile.Name)%><strong><%=theFile.Name%></strong></a>
				  </td>
				  <td align="center" style="padding:0 8px; white-space:nowrap"><%=theFile.size%>字节</td>
				  <td align="center" style="padding:0 8px; white-space:nowrap"><%=theFile.type%></td>
				  <td align="center" style="padding:0 8px; white-space:nowrap"><%=theFile.DateLastModified%></td>
				  <td align="center" style="padding:0 8px; white-space:nowrap"><a href="UploadFileManage.asp?action=Del&FileName=<%=UploadDir&theFile.Name%>&goDir=<%=goDir%>" onClick="return confirm('确定删除该文件？')">删除</a></td>
				</tr>
				<%
				FileCount=FileCount+1
				TotleSize=TotleSize+theFile.Size
			end if
		Next
		%>
      </table>
<%
end sub
%>

<%
sub showpage2(sfilename,totalnumber,maxperpage)
    if goDir<>"" then qryString="&goDir="&goDir
	dim n, i,strTemp
	if totalnumber mod maxperpage=0 then
    	n= totalnumber \ maxperpage
  	else
    	n= totalnumber \ maxperpage+1
  	end if
  	strTemp= "<div align='center'>"
	strTemp=strTemp & "共 <b>" & totalnumber & "</b> 个文件，占用 <b>" & TotleSize\1024 & "</b> K&nbsp;&nbsp;&nbsp;"
	sfilename=JoinChar(sfilename)
  	if CurrentPage<2 then
    		strTemp=strTemp & "首页 上一页&nbsp;"
  	else
    		strTemp=strTemp & "<a href='" & sfilename & "page=1" & qryString & "'>首页</a>&nbsp;"
    		strTemp=strTemp & "<a href='" & sfilename & "page=" & (CurrentPage-1) & qryString & "'>上一页</a>&nbsp;"
  	end if

  	if n-currentpage<1 then
    		strTemp=strTemp & "下一页 尾页"
  	else
    		strTemp=strTemp & "<a href='" & sfilename & "page=" & (CurrentPage+1) & qryString & "'>下一页</a>&nbsp;"
    		strTemp=strTemp & "<a href='" & sfilename & "page=" & n & qryString & "'>尾页</a>"
  	end if
   	strTemp=strTemp & "&nbsp;页次：<strong><font color=red>" & CurrentPage & "</font>/" & n & "</strong>页 "
    strTemp=strTemp & "&nbsp;<b>" & maxperpage & "</b>" & "个文件/页"
	strTemp=strTemp & "&nbsp;转到：<select name='page' size='1' onchange=location='"&sfilename&"page='+this.value+'"&qryString&"'>"   
    for i = 1 to n   
   		strTemp=strTemp & "<option value='" & i & "'"
		if cint(CurrentPage)=cint(i) then strTemp=strTemp & " selected "
		strTemp=strTemp & ">第" & i & "页</option>"   
	next
	strTemp=strTemp & "</select>"
	strTemp=strTemp & "</div>"
	response.write strTemp
end sub

sub getFileIco(filename)
	fileNameType=lcase(mid(filename,instrrev(filename,".")))
	dim icoStr,icoClass
	select case lcase(fileNameType)
	case ".txt":icoClass="fileIco fileTxt"
	case ".jpg",".gif",".png",".bmp",".jpeg":icoClass="fileIco fileImg"
	case ".pdf":icoClass="fileIco filePdf"
	case ".doc",".docx":icoClass="fileIco fileDoc"
	case ".xls",".xlsx":icoClass="fileIco fileXls"
	case ".ppt",".pptx":icoClass="fileIco filePPT"
	case ".zip":icoClass="fileIco fileZip"
	case ".rar":icoClass="fileIco fileRar"
	case ".swf",".flv",".fla":icoClass="fileIco fileFla"
	case ".rmvb",".avi",".mpg",".wmv",".mp3",".wma",".midi",".mmf",".amr",".wav",".aac":icoClass="fileIco fileMedia"
	case else:icoClass="fileIco files"
	end select
	icoStr="<span class='"&icoClass&"'></span>"
	Response.Write icoStr
end sub
%>
	</div>
</body>
</html>